package com.tensquare.search.controller;

import com.tensquare.search.pojo.Article;
import com.tensquare.search.service.ArticleSearchService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("article")
public class ArticleSearchController {
    @Autowired
    private ArticleSearchService articleSearchService;
    //1.添加文章
    @PostMapping
    public Result add(@RequestBody Article article){
        articleSearchService.add(article);
        return new Result(true,StatusCode.OK,"添加成功");
    }
    //2. 关键字查询
    @GetMapping("/search/{keywords}/{page}/{size}")
    public Result search(@RequestBody String keywords,@PathVariable int page,@PathVariable int size){
        PageResult<Article> pageResult = articleSearchService.search(keywords,page,size);
        return new Result(true,StatusCode.OK,"添加成功",pageResult);
    }
}
